#include <TGS/MapControl2.0/RenderContext.h>

namespace TGS{
namespace MapControl{
	

struct RenderContext::RenderContextPrivate
{
	/**Painter for rendering operations*/
	QPainter*	_painter;
	Envelope	_extent;
	/**If true then no rendered vector elements should be cached as image*/
	bool		_forceVectorOutput;
	MapToPixel	_mapToPixel;
	/**True if the rendering has been canceled*/
	bool		_renderingStopped;
	/**Factor to scale line widths and point marker sizes*/
	double		_scaleFactor;
	/**Factor to scale rasters*/
	double		_rasterScaleFactor;
	/**Map scale*/
	double		_rendererScale;
};

RenderContext::RenderContext()
	: _data(new RenderContextPrivate())
{
	_data->_painter = nullptr;
	_data->_forceVectorOutput = false;
	_data->_renderingStopped = false;
	_data->_scaleFactor = 1.0;
	_data->_rasterScaleFactor = 1.0;
}

RenderContext::~RenderContext()
{
	if(nullptr != _data)
	{
		delete _data;
		_data = nullptr;
	}
}

inline QPainter* RenderContext::painter() { return _data->_painter;}
inline const QPainter* RenderContext::constPainter() const { return _data->_painter; }

inline const RenderContext::Envelope& RenderContext::extent() const {return _data->_extent;}

inline const MapToPixel& RenderContext::mapToPixel() const {return _data->_mapToPixel;}

inline double RenderContext::scaleFactor() const {return _data->_scaleFactor;}

inline double RenderContext::rasterScaleFactor() const {return _data->_rasterScaleFactor;}

inline bool RenderContext::renderingStopped() const {return _data->_renderingStopped;}

inline bool RenderContext::forceVectorOutput() const {return _data->_forceVectorOutput;}

inline double RenderContext::rendererScale() const {return _data->_rendererScale;}

//setters

/**Sets coordinate transformation. QgsRenderContext takes ownership and deletes if necessary*/
void RenderContext::setMapToPixel( const MapToPixel& mtp ) {_data->_mapToPixel = mtp;}
void RenderContext::setExtent( const Envelope& extent ) {_data->_extent = extent;}
void RenderContext::setRenderingStopped( bool stopped ) {_data->_renderingStopped = stopped;}
void RenderContext::setScaleFactor( double factor ) {_data->_scaleFactor = factor;}
void RenderContext::setRasterScaleFactor( double factor ) {_data->_rasterScaleFactor = factor;}
void RenderContext::setRendererScale( double scale ) {_data->_rendererScale = scale;}
void RenderContext::setPainter( QPainter* p ) {_data->_painter = p;}
void RenderContext::setForceVectorOutput( bool force ) {_data->_forceVectorOutput = force;}

}//MapControl
}//TGS